import { WeaAlertPage, WeaLocaleProvider } from 'ecCom';
import { Spin } from 'antd';
import { inject, observer } from 'mobx-react';
import ReplyItem from '../item/';
import { toJS } from 'mobx';

const getLabel = WeaLocaleProvider.getLabel;

@inject('coworkMainStore')
@observer
class ReplyList extends React.Component {
	constructor(props) {
		super(props);
	}
	// 移到store的chooseCowork中。
	componentDidMount() {
    const { coworkMainStore } = this.props;
    coworkMainStore.reloadRecordList();
  }
  componentWillReceiveProps(nextProps) {
    if (nextProps.coworkId != this.props.coworkId) {
      const { coworkMainStore } = this.props;
      coworkMainStore.reloadRecordList();
    }
  }
	render() {
    const { coworkMainStore, batchOperate, isCanAnonymous, canReply, itemapprovalAtatus } = this.props;
    let { content } = coworkMainStore;
    content = toJS(content);
    let { recordList = [], replyListViewRight = 0, checkIds, recordLoading, cowork } = content;
    if (replyListViewRight != 1) {
      return <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@ai2874`} style={{ height: 200, position: 'relative', paddingTop: '50px' }}><div>{getLabel(382663, '暂无权限')}</div></WeaAlertPage>;
    }
		return (
			<div className="wea-cowork-reply-list">
        <div>
          {recordLoading ? <div style={{ height: window.innerHeight }}><div className="top40 align-center" style={{ position: 'relative' }}><Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@96f483`} tip={`${getLabel(31230, '加载中')}...`} /></div></div> :
            recordList && recordList.length > 0 ? recordList.map((record) => {
              let checked = checkIds.some(id => record.id == id);
              return (<ReplyItem ecId={`${this && this.props && this.props.ecId || ''}_ReplyItem@t2qaka@${record.id}`}
                {...record}
                batchOperate={batchOperate}
                operate={coworkMainStore.operateDicsuss}
                submit={this.props.submit}
                isCanAnonymous={isCanAnonymous}
                itemapprovalAtatus={itemapprovalAtatus}
                check={this.check}
                canReply={canReply}
                checked={checked}
                isCoworkTypeApprove={cowork.isCoworkTypeApprove}
              />);
            }) : (
              <div style={{ height: window.innerHeight }}>
                <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@a97i15`} icon="icon-coms-blank" paddingTop="40px">
                  <div>{getLabel(83553, '暂无数据')}</div>
                </WeaAlertPage>
              </div>
            )
          }
        </div>
      </div>
		);
	}

  changePage = (current) => {
    const { coworkMainStore } = this.props;
    coworkMainStore.queryRecordList({ currentPage: current }, this.props.scrollToTop);
  }
  check = (id, bool) => {
    const { coworkMainStore } = this.props;
    coworkMainStore.check(id, bool);
  }
}
export default ReplyList;
